import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution228 {

    public static void main(String args[]) {
        Solution228 s = new Solution228();
        System.out.println(s.summaryRanges(new int[]{1,2,3}));
    }

    public List<String> summaryRanges(int[] nums) {
        List<String> ret = new ArrayList<String>();
        if (nums.length == 0) {
            return ret;
        }
        int l = nums[0];
        int r = nums[0];

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i - 1] == 1) {
                r = nums[i];
            } else {
                String t1 = format(l, r);
                ret.add(t1);
                l = nums[i];
                r = nums[i];
            }
        }
        ret.add(format(l, r));
        return ret;
    }

    public String format(int l, int r) {
        if (l == r) {
            return l + "";
        } else {
            return l + "->" + r;
        }
    }

}
